/**
 * Created by zhu on 2015/12/29.
 */
$(function(){
    var myhregf = window.location.href;
    var count = myhregf.split('/').length;
    var id = myhregf.split('/')[count-1];
    $('#now_buy').on('click',function(){
        window.location.href=contextPath+'/cart/orderConfirmation/'+id;
    });
    $.get(contextPath + "/goods/detail/goods/"+id, function (data) {
        loadGoodDetail(data);
    });

    $.get(contextPath + "/goods/detail/image/"+id, function (data) {
        loadImage(data);
    });

});

function loadGoodDetail(data){

    data =  jQuery.parseJSON(data);
    if(data.status == 1){

    }else{
        $('#goodsName').text(data.bean.name);

        $('#goodsPrice').text(data.bean.price);

        $('#goodsNumber').text(data.bean.goods_number);
    }

}

function loadImage(data){
    data =  jQuery.parseJSON(data);
    if(data.status == 1){

    }else{
        var goodsgalley = $('#goodsGalley');
        goodsgalley.empty();
        $.each(data.list,function(i,item){
            if(item.imageUser == "goodsGalley"){
                var mydiv = "";
                mydiv += ' <div class="swiper-slide"><img src="'+contextPath+item.url+'" alt=""></div>';
                goodsgalley.append(mydiv);
            }


        });
    }
}